package com.atguigu.gmall.scheduled;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/5/30 14:39
 * @Version 1.0
 */
@EnableScheduling
@Component
@Slf4j
public class ScheduledTask {

    @Autowired
    private RabbitService rabbitService;
    //  自定义一个定时任务.
    @Scheduled(cron = "0/10 * * * * ?")
    public void test(){
        log.info("执行任务....");
        System.out.println("--task--");
        //  发生消息给秒杀模块.
        rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_1,"ok");
    }

    //  数据量太大了，可以做定期的数据迁移.
    @Scheduled(cron = "0/30 * * * * ?")
    public void test1(){
        log.info("执行任务....");
        System.out.println("--task--");
        //  发生消息给秒杀模块.
        rabbitService.sendMsg(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_18,"");
    }

}
